/****************************************************
	文件：BindPrefabCtrl.cs
	作者：HuskyT
	邮箱：1005240602@qq.com
	日期：2021/1/14 21:22:55
	功能：绑定预制体 控制器
*****************************************************/

using System;
using System.Collections.Generic;
using HTFW.Utility.Global;

namespace HTFW.Core
{
    public class BindPrefabCtrl : IDisposable
    {
        Dictionary<Type, string> mBindDict = new Dictionary<Type, string>();

        public void Bind(Type type, string path)
        {
            if (mBindDict.ContainsKey(type))
            {
                mBindDict[type] = path;
            }
            else
            {
                mBindDict.Add(type, path);
            }
        }

        public string GetPath(Type type)
        {
            if (mBindDict.TryGetValue(type, out string path))
            {
                return path;
            }

            return string.Empty;
        }

        public bool TryGetPath(Type type, out string path)
        {
            if (mBindDict.TryGetValue(type, out path))
            {
                return true;
            }

            path = string.Empty;
            return false;
        }

        public string GetPath<T>()
        {
            if (mBindDict.TryGetValue(typeof(T), out string path))
            {
                return path;
            }

            return string.Empty;
        }

        public bool TryGetPath<T>(out string path)
        {
            if (mBindDict.TryGetValue(typeof(T), out path))
            {
                return true;
            }

            path = string.Empty;
            return false;
        }

        public void Dispose()
        {
            mBindDict.Clear();
        }
    }
}